import java.util.*;
public class Demo1 {

    public static int MoreThanHalfNum_Solution(int [] array) {
        int tmp = array[0];
        int times = 1;
        for (int i = 1; i < array.length; i++) {
            if (times == 0) {
                tmp = array[i];
                times = 1;
            }
            else if (array[i] == tmp) {
                times++;
            } else {
                times--;
            }
        }
        int count = 0;
        for (int i = 0; i < array.length; i++) {
            if (array[i] == tmp) {
                count++;
            }
        }
        if (count > (array.length >> 1)) return tmp;
        return 0;
    }
    public static void main3(String[] args) {
        int[] array = {1,2,3,4,5,5};
        MoreThanHalfNum_Solution(array);
    }
    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
            String str = in.nextLine();
            String a[] = str.split(" ");
            StringBuffer stringBuffer = new StringBuffer("");
            for(int i = a.length-1;i>=0;i--) {
                stringBuffer.append(a[i]);
            }
        System.out.println(stringBuffer.toString());
    }
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] array = new int[n+1];
        for (int i = 0; i < n; i++) {
            array[i] = in.nextInt();
        }
        int i = 0;
        int count = 0;
        while (i<n) {
            if(array[i+1] > array[i]) {
                while (i<n && array[i+1] >= array[i]) {
                    i++;
                }
                i++;
                count++;
            }else if(array[i+1] == array[i]){
                i++;
            }else {
                while (i<n && array[i] >= array[i+1]) {
                    i++;
                }
                i++;
                count++;
            }
        }
        System.out.println(count);
    }
}
